package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zmht.beike.biz.CMonthinfoBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.TCmonthinfo;

public class CMonthinfoBizImpl extends BaseBizImpl implements CMonthinfoBiz {

	public List getMonthinfo(Integer teacherId, int startIndex, int pageSize) {
		//this.getCmonthinfoDAO().findByHQLObj("from TCmonthinfo t where t.teacherId="+teacherId);
		String hql = "from TCmonthinfo t where t.teacherId="+teacherId+" order by t.id desc";
		return this.getCmonthinfoDAO().findByPage(hql, startIndex, pageSize);

	}

	public int getMonthinfoTotal(Integer teacherId) {
		String hql = "from TCmonthinfo t where t.teacherId="+teacherId;
		return this.getCmonthinfoDAO().findByHQLObj(hql).size();
	}
	/**
	 * 保存记录
	 * @param cmonthinfo
	 * @return
	 */
	public Integer saveMonthinfo(TCmonthinfo cmonthinfo){
		try{
			return (Integer)this.getCmonthinfoDAO().saveObj(cmonthinfo);
		}catch(Exception e){
			return 0;
		}
		
	}
	public TCmonthinfo findTcmonth(Serializable id) {
	
		return (TCmonthinfo)this.getCmonthinfoDAO().findById(TCmonthinfo.class, id);
	}
	/**
	 * 测试
	 * @param args
	 */
	public static void main(String [] args){
		ApplicationContext cxt;
		cxt = new ClassPathXmlApplicationContext(new String[]{"spring/spring.xml","spring/spring_dao.xml","spring/spring_beike.xml",});
	
		CMonthinfoBizImpl biz  = (CMonthinfoBizImpl)cxt.getBean("cmonthinfoBizTag");
/*		System.out.println(biz);
		List list = biz.getMonthinfo(3, 0, 100);
		int total = biz.getMonthinfoTotal(3);
		System.out.println(total);*/
		//查询总记录
		System.out.println(biz.getMonthinfoTotal(3));
		
		
		//保存月主题
		/*TCmonthinfo cmonthinfo = new TCmonthinfo();
		cmonthinfo.setTeacherId(3);
		cmonthinfo.setMonth(1);
		cmonthinfo.setMonthThemeName("测试月主题");
		cmonthinfo.setTerm(2);
		cmonthinfo.setCaimId(2);
		
		Integer rs = biz.saveMonthinfo(cmonthinfo);
		System.out.println(rs);*/
		
	}

	public List findByHQL(String hql) {
		return this.getCmonthinfoDAO().findByHQLObj(hql);

	}

	
}
